package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC668 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int findKthNumber(int m, int n, int k) {
            int left = 1, right = m * n;
            while (left < right) {
                //计算x，也就是二分的mid
                int x = left + (right - left) / 2;
                int count = 0;
                //计算每一行小于等于x的个数
                for (int i = 1; i <= m; i++) {
                    count += Math.min(x / i, n);
                }
                //二分法查找第k小
                if (count >= k) {
                    right = x;
                } else {
                    left = x + 1;
                }
            }
            return left;
        }
    }


    public void run() {
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(new Solution().toString());
    }

    public static void main(String[] args) throws Exception {
        LC668 an = new LC668();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
